package com.shsmi.application;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.shsmi.entity.CityPoint;
import com.shsmi.entity.CityRegion;
import com.shsmi.entity.GeoRegion;
import com.shsmi.entity.GeoPoint;
import com.shsmi.util.CoordinateTransformUtils;
import com.shsmi.util.GaussXYDeal;
import com.shsmi.util.GenerateToken;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.*;
import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@ApiOperation(value = "坐标转换")
public class CoordsConvert {
    public String OneMapHost = "http://10.87.94.143";
//    String OneMapHost = "http://10.108.3.36";


    @GetMapping("/public/getToken")
    @ApiOperation(value = "获取Token") // 让Swagger-UI解析这个接口。
    public String returnToken() {
        return GenerateToken.tokenStr;
    }

    @PostMapping("/public/cgcs2city")
    @ApiOperation(value = "CGCS2000转上海城市坐标")
    public CityPoint cgcs2city(@RequestParam("lon") double lon, @RequestParam("lat") double lat) {
        return getCityByCgcs(lon, lat);
    }

    @PostMapping("/public/city2cgcs")
    @ApiOperation(value = "上海城市坐标转CGCS2000")
    public GeoPoint city2cgcs(@RequestParam("x") String x, @RequestParam("y") String y) {
        JSONObject jsonObject = new JSONObject();
        GeoPoint newGeoPoint = new GeoPoint();
//        BigDecimal bigx=;
//        BigDecimal bigY=new BigDecimal(y).multiply(new BigDecimal("180")).divide(new BigDecimal(Math.PI),9,BigDecimal.ROUND_HALF_UP);
        //申请token
        if (GenerateToken.tokenStr == null) {
            GenerateToken.generateToken();
        }
        try {
            //构造SOAP请求
            String strsoap = "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap" +
                    ".org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www." +
                    "w3.org/2001/XMLSchema\">";
            //本示例为CGCS2000转上海城市坐标
            //三个参数解释:arg0:北纬【弧度】 arg1:东经【弧度】 arg3:高程【0】
//            strsoap += "<soap:Body><WGS84BLH2SH xmlns=\"SHCoordTransM1WS\"><arg0 xmlns=\"\">0.5451543806</arg0><arg1 xmlns=\"\">2.1203611989</arg1><arg2 xmlns=\"\">0</arg2></WGS84BLH2SH></soap:Body></soap:Envelope>";
            //本示例为上海城市坐标转CGCS2000
            strsoap += "<soap:Body><SH2WGS84BLH xmlns=\"SHCoordTransM1SW\"><arg0 xmlns=\"\">" + x + "</arg0>" +
                    "<arg1 xmlns=\"\">" + y + "</arg1><arg2 xmlns=\"\">0</arg2></SH2WGS84BLH></soap:Body></soap:Envelope>";

            // HTTP请求的url
            //本示例为CGCS2000转上海城市坐标
//            URL soapurl = new URL(OneMapHost + "/OneMapServer/rest/services/coordtransm1ws/Transfer");
            //本示例为上海城市坐标转CGCS2000
            URL soapurl = new URL(OneMapHost + "/OneMapServer/rest/services/coordtransm1sw/Transfer");

            // 打开连接
            HttpURLConnection connection = (HttpURLConnection) soapurl.openConnection();
            // 设置cookie
            connection.setRequestProperty("Cookie", "agstoken=" + GenerateToken.tokenStr + ";");
            // 设置referer,取值要和获取token时clientId的取值保持一致
            connection.setRequestProperty("referer", "http://127.0.0.1");
            // 配置本次连接的Content-type
            connection.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
            // 设置是否向connection输出，因为这个是post请求，参数要放在http正文内，因此需要设为true
            connection.setDoOutput(true);
            // 默认是GET方式
            connection.setRequestMethod("POST");
            // Post请求不能使用缓存
            connection.setUseCaches(false);
            // 与服务器建立TCP连接
            connection.connect();

            DataOutputStream out = new DataOutputStream(connection.getOutputStream());
            out.writeBytes(strsoap);
            out.flush();
            out.close();

		/* 返回的结果XML
		本示例为CGCS2000转上海城市坐标
		<?xml version="1.0" ?>
		<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
			<S:Body>
				<ns2:WGS84BLH2SHResponse xmlns:ns2="SHCoordTransM1WS">
					<return>-44.015064392097436</return>
					<return>1961.1260791703294</return>
					<return>0.0</return>
				</ns2:WGS84BLH2SHResponse>
			</S:Body>
		</S:Envelope>

		本示例为CGCS2000转上海城市坐标
		<?xml version="1.0" encoding="utf-8"?>
		<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
			<soap:Body>
				<SH2WGS84BLH xmlns="SHCoordTransM1SW">
					<arg0 xmlns="">0.5451543806</arg0>
					<arg1 xmlns="">2.1203611989</arg1>
					<arg2 xmlns="">0</arg2>
				</SH2WGS84BLH>
			</soap:Body>
		</soap:Envelope>
		*/
            //发出坐标转换的HTTP请求
            BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
            String line;
            StringBuffer response = new StringBuffer();
            //获取服务器的返回
            while ((line = reader.readLine()) != null) {
                response.append(line);
            }
            reader.close();
            //断开连接
            connection.disconnect();

            //创建DOM解析器工厂实例并生成解析器
            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
            //解析文档，并返回一个Document对象，此时xml文档已加载到内存中
            Document doc = dBuilder.parse(new InputSource(new StringReader(response.toString())));
            //获取文档根元素
            Element root = doc.getDocumentElement();
            NodeList list = root.getElementsByTagName("return");
            newGeoPoint.setLon(Double.valueOf(new BigDecimal(list.item(0).getTextContent()).multiply(new BigDecimal("180")).divide(new BigDecimal(Math.PI), 9, BigDecimal.ROUND_HALF_UP).doubleValue()));
            newGeoPoint.setLat(Double.valueOf(new BigDecimal(list.item(1).getTextContent()).multiply(new BigDecimal("180")).divide(new BigDecimal(Math.PI), 9, BigDecimal.ROUND_HALF_UP).doubleValue()));

//            jsonObject.put("lon", Double.valueOf(new BigDecimal(list.item(0).getTextContent()).multiply(new BigDecimal("180")).divide(new BigDecimal(Math.PI), 9, BigDecimal.ROUND_HALF_UP).doubleValue()));
//            jsonObject.put("lat", Double.valueOf(new BigDecimal(list.item(1).getTextContent()).multiply(new BigDecimal("180")).divide(new BigDecimal(Math.PI), 9, BigDecimal.ROUND_HALF_UP).doubleValue()));
//            System.out.println("返回值1:" + list.item(0).getTextContent() + " " + "返回值2:" + list.item(1).getTextContent());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return newGeoPoint;
    }

    @PostMapping("/public/cgcs2city2")
    @ApiOperation(value = "CGCS2000转上海城市坐标（非接口）")
    public CityPoint cgcs2city2(@RequestParam("lon") double lon, @RequestParam("lat") double lat) {
        CityPoint cityPoint = GaussXYDeal.BLToGauss(lon,lat);
        return cityPoint;
    }

    @PostMapping("/public/city2cgcs2")
    @ApiOperation(value = "上海城市坐标转CGCS2000（非接口）")
    public GeoPoint city2cgcs2(@RequestParam("x") String x, @RequestParam("y") String y) {
        GeoPoint geoPoint = new GeoPoint();
        try {
            geoPoint = GaussXYDeal.GaussToBL(Double.parseDouble(x), Double.parseDouble(y));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return geoPoint;
    }

    /**
     * @param addrName
     * @param num
     * @return
     * @throws IOException
     * @throws ParserConfigurationException
     * @throws SAXException
     */
    @PostMapping("/public/parseAddress")
    @ApiOperation(value = "地名地址解析")
    public String addrOrAddrName(@RequestParam("addrName") String addrName, @RequestParam("num") String num) throws IOException, ParserConfigurationException, SAXException {
        JSONArray jsonArray = new JSONArray();
        //构造地名地址查询的SOAP请求
        if (GenerateToken.tokenStr == null) {
            GenerateToken.generateToken();
        }
        String addresssoap = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
                "xmlns:s=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/" +
                "XMLSchema-instance\">";
        addresssoap += "<SOAP-ENV:Body><tns:ASCH_AddressSearch xmlns:tns=\"http://tempuri.org/\">" +
                "<tns:vSearch_word>" + addrName + "</tns:vSearch_word><tns:vResult_count>" + num + "</tns:vResult_count>" +
                "</tns:ASCH_AddressSearch></SOAP-ENV:Body></SOAP-ENV:Envelope>";
        // HTTP请求的url
        URL addressurl = new URL(OneMapHost + "/OneMapServer/rest/services/address_p/Transfer");
        // 打开连接
        HttpURLConnection connection = (HttpURLConnection) addressurl.openConnection();
        // 设置cookie
        connection.setRequestProperty("Cookie", "agstoken=" + GenerateToken.tokenStr + ";");
        // 设置referer,取值要和获取token时clientId的取值保持一致
        connection.setRequestProperty("referer", "http://127.0.0.1");
        // 配置本次连接的Content-type
        connection.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
        // 设置是否向connection输出，因为这个是post请求，参数要放在http正文内，因此需要设为true
        connection.setDoOutput(true);
        // 默认是GET方式
        connection.setRequestMethod("POST");
        // Post请求不能使用缓存
        connection.setUseCaches(false);

        // 与服务器建立TCP连接
        connection.connect();

        DataOutputStream out = new DataOutputStream(connection.getOutputStream());
        out.write(addresssoap.getBytes("utf-8"));
        out.flush();
        out.close();

        //发出地址查询的HTTP请求
        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
        String line;
        StringBuffer response = new StringBuffer();
        //获取服务器的返回
        while ((line = reader.readLine()) != null) {
            response.append(line);
        }
        reader.close();
        //断开连接
        connection.disconnect();

        //创建DOM解析器工厂实例并生成解析器
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        //解析文档，并返回一个Document对象，此时xml文档已加载到内存中
        Document doc = dBuilder.parse(new InputSource(new StringReader(response.toString())));
        //获取文档根元素
        Element root = doc.getDocumentElement();
        NodeList list = root.getElementsByTagName("Table");
        System.out.println("找到" + list.getLength() + "个结果");
        //遍历每一个节点
        for (int i = 0; i < list.getLength(); ++i) {
            //获得元素，将节点强制转换为元素
            Element element = (Element) list.item(i);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("REGION_QX", element.getElementsByTagName("REGION_QX").item(0).getFirstChild().getNodeValue());
            jsonObject.put("ROAD1", element.getElementsByTagName("ROAD1").getLength() > 0 ? element.getElementsByTagName("ROAD1").item(0).getFirstChild().getNodeValue() : "");
            jsonObject.put("ROAD2", element.getElementsByTagName("ROAD2").getLength() > 0 ? element.getElementsByTagName("ROAD2").item(0).getFirstChild().getNodeValue() : "");
            jsonObject.put("ADDRESS", element.getElementsByTagName("ADDRESS").getLength() > 0 ? element.getElementsByTagName("ADDRESS").item(0).getFirstChild().getNodeValue() : "");
            jsonObject.put("POI", element.getElementsByTagName("POI").getLength() > 0 ? element.getElementsByTagName("POI").item(0).getFirstChild().getNodeValue() : "");
            jsonObject.put("POINT_Y", element.getElementsByTagName("POINT_Y").getLength() > 0 ? element.getElementsByTagName("POINT_Y").item(0).getFirstChild().getNodeValue() : "");
            jsonObject.put("POINT_X", element.getElementsByTagName("POINT_X").getLength() > 0 ? element.getElementsByTagName("POINT_X").item(0).getFirstChild().getNodeValue() : "");
            jsonObject.put("SMICODE_XY", element.getElementsByTagName("SMICODE_XY").getLength() > 0 ? element.getElementsByTagName("SMICODE_XY").item(0).getFirstChild().getNodeValue() : "");
            jsonObject.put("CLS", element.getElementsByTagName("CLS").getLength() > 0 ? element.getElementsByTagName("CLS").item(0).getFirstChild().getNodeValue() : "");
            jsonObject.put("SOURCETABLE", element.getElementsByTagName("SOURCETABLE").getLength() > 0 ? element.getElementsByTagName("SOURCETABLE").item(0).getFirstChild().getNodeValue() : "");
            jsonObject.put("MACCURACY", element.getElementsByTagName("MACCURACY").getLength() > 0 ? element.getElementsByTagName("MACCURACY").item(0).getFirstChild().getNodeValue() : "");
            jsonArray.add(jsonObject);
            System.out.println("横坐标:" + element.getElementsByTagName("POINT_X").item(0).getFirstChild()
                    .getNodeValue() + " 纵坐标:" + element.getElementsByTagName("POINT_Y").item(0).getFirstChild().getNodeValue());
        }
        return jsonArray.toString();
    }

    @PostMapping("/public/coordinateConversionArray")
    @ApiOperation(value = "批量进行坐标转换-CGCS2000转上海")
    public String coordinateConversionArray(@RequestBody List<Map> list) {
        List retList = new ArrayList();
        list.stream().forEach(m -> {
            retList.add(getCityByCgcs(Double.valueOf(m.get("lon").toString()), Double.valueOf(m.get("lat").toString())));
        });

        return retList.toString();
    }

    @PostMapping("/public/gcj2cgcs")
    @ApiOperation(value = "火星坐标转CGCS2000")
    public GeoPoint gcj2cgcs(@RequestParam("lon") double lon, @RequestParam("lat") double lat) {
        return CoordinateTransformUtils.gcj02ToWgs84Exactly(lon, lat);
    }

    @PostMapping("/public/cgcs2gcj")
    @ApiOperation(value = "CGCS2000转火星坐标")
    public GeoPoint cgcs2gcj(@RequestParam("lon") double lon, @RequestParam("lat") double lat) {
        return CoordinateTransformUtils.wgs84ToGcj02(lon, lat);
    }

    @PostMapping("/public/bd2cgcs")
    @ApiOperation(value = "百度转CGCS2000")
    public GeoPoint cgcs2bd(@RequestParam("lon") double lon, @RequestParam("lat") double lat) {
        return CoordinateTransformUtils.bd09ToWgs84(lon, lat);
    }

    @PostMapping("/public/cgcs2bd")
    @ApiOperation(value = "CGCS2000转百度")
    public GeoPoint bd2cgcs(@RequestParam("lon") double lon, @RequestParam("lat") double lat) {
        return CoordinateTransformUtils.wgs84ToBd09(lon, lat);
    }


    @PostMapping("/public/gridNo2geoRegion")
    @ApiOperation(value = "格网编号获取CGCS2000坐标下格网范围")
    public GeoRegion gridNo2geoRegion(@RequestParam("gridNo") String gridNo) {
        GeoPoint centerPt = CoordinateTransformUtils.gcj02ToWgs84Exactly(parseGridNo(gridNo).getLon(), parseGridNo(gridNo).getLat());
        GeoRegion newGeoRegion = new GeoRegion();
        newGeoRegion.setMaxLat(centerPt.getLat() + 0.000005);
        newGeoRegion.setMinLat(centerPt.getLat() - 0.000005);
        newGeoRegion.setMaxLon(centerPt.getLon() + 0.000005);
        newGeoRegion.setMinLon(centerPt.getLon() - 0.000005);
        return newGeoRegion;
    }

    @PostMapping("/public/gridNo2cityRegion")
    @ApiOperation(value = "格网编号获取上海城建坐标格网范围")
    public CityRegion gridNo2CityRegion(@RequestParam("gridNo") String gridNo) {
        GeoPoint gridCenterPt=parseGridNo(gridNo);
        GeoPoint centerPt = CoordinateTransformUtils.gcj02ToWgs84Exactly(gridCenterPt.getLon(), gridCenterPt.getLat());
        CityPoint centerCityPt = getCityByCgcs(centerPt.getLon(), centerPt.getLat());
        // 注意异步问题、是否利用离线的高斯正反算
        CityRegion newCityRegion = new CityRegion();
        newCityRegion.setMaxX(centerCityPt.getX() + 0.5);
        newCityRegion.setMinX(centerCityPt.getX() - 0.5);
        newCityRegion.setMaxY(centerCityPt.getY() + 0.5);
        newCityRegion.setMinY(centerCityPt.getY() - 0.5);
        return newCityRegion;
    }


    @PostMapping("/public/gridNo2cgcs")
    @ApiOperation(value = "格网编号转CGCS2000")
    public GeoPoint gridNo2cgcs(@RequestParam("gridNo") String gridNo) {
        GeoPoint gridCenterPt=parseGridNo(gridNo);
        return CoordinateTransformUtils.gcj02ToWgs84Exactly(gridCenterPt.getLon(), gridCenterPt.getLat());
    }

    @PostMapping("/public/gridNo2city")
    @ApiOperation(value = "格网编号转上海城建坐标")
    public CityPoint gridNo2city(@RequestParam("gridNo") String gridNo) {
        GeoPoint gridCenterPt=parseGridNo(gridNo);
        GeoPoint pt = CoordinateTransformUtils.gcj02ToWgs84Exactly(gridCenterPt.getLon(), gridCenterPt.getLat());
        return getCityByCgcs(pt.getLon(), pt.getLat());
    }

    public  CityPoint getCityByCgcs(double lon, double lat) {
        BigDecimal bigx = new BigDecimal(lon).multiply(new BigDecimal(Math.PI)).divide(new BigDecimal("180"), 9, BigDecimal.ROUND_HALF_UP);
        BigDecimal bigY = new BigDecimal(lat).multiply(new BigDecimal(Math.PI)).divide(new BigDecimal("180"), 9, BigDecimal.ROUND_HALF_UP);
        //申请token//如果提示登录了就再跑一遍token
        if (GenerateToken.tokenStr == null) {
            GenerateToken.generateToken();
        }
        CityPoint newCityPoint = new CityPoint();
        try {
            //构造SOAP请求
            String strsoap = "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://schemas." +
                    "xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:" +
                    "xsd=\"http://www.w3.org/2001/XMLSchema\">";
            //本示例为CGCS2000转上海城市坐标
            //三个参数解释:arg0:北纬【弧度】 arg1:东经【弧度】 arg3:高程【0】
            strsoap += "<soap:Body><WGS84BLH2SH xmlns=\"SHCoordTransM1WS\"><arg0 xmlns=\"\">" + bigY + "</arg0>" +
                    "<arg1 xmlns=\"\">" + bigx + "</arg1><arg2 xmlns=\"\">0</arg2></WGS84BLH2SH></soap:Body></soap:Envelope>";
            //本示例为上海城市坐标转CGCS2000
            //strsoap += "<soap:Body><SH2WGS84BLH xmlns=\"SHCoordTransM1SW\"><arg0 xmlns=\"\">-45.8249546177473</arg0><arg1 xmlns=\"\">1963.93771569366</arg1><arg2 xmlns=\"\">0</arg2></SH2WGS84BLH></soap:Body></soap:Envelope>";

            // HTTP请求的url
            //本示例为CGCS2000转上海城市坐标
            URL soapurl = new URL(OneMapHost + "/OneMapServer/rest/services/coordtransm1ws/Transfer");
            //本示例为上海城市坐标转CGCS2000
            //URL soapurl = new URL(OneMapHost + "/OneMapServer/rest/services/coordtransm1sw/Transfer");

            // 打开连接
            HttpURLConnection connection = (HttpURLConnection) soapurl.openConnection();
            // 设置cookie
            connection.setRequestProperty("Cookie", "agstoken=" + GenerateToken.tokenStr + ";");
            // 设置referer,取值要和获取token时clientId的取值保持一致
            connection.setRequestProperty("referer", "http://127.0.0.1");
            // 配置本次连接的Content-type
            connection.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
            // 设置是否向connection输出，因为这个是post请求，参数要放在http正文内，因此需要设为true
            connection.setDoOutput(true);
            // 默认是GET方式
            connection.setRequestMethod("POST");
            // Post请求不能使用缓存
            connection.setUseCaches(false);
            // 与服务器建立TCP连接
            connection.connect();

            DataOutputStream out = new DataOutputStream(connection.getOutputStream());
            out.writeBytes(strsoap);
            out.flush();
            out.close();

            //发出坐标转换的HTTP请求
            BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
            String line;
            StringBuffer response = new StringBuffer();
            //获取服务器的返回
            while ((line = reader.readLine()) != null) {
                response.append(line);
            }
            reader.close();
            //断开连接
            connection.disconnect();
            //创建DOM解析器工厂实例并生成解析器
            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
            //解析文档，并返回一个Document对象，此时xml文档已加载到内存中
            Document doc = dBuilder.parse(new InputSource(new StringReader(response.toString())));
            //获取文档根元素
            Element root = doc.getDocumentElement();
            NodeList list = root.getElementsByTagName("return");
            newCityPoint.setX(Double.valueOf(list.item(1).getTextContent()));
            newCityPoint.setY(Double.valueOf(list.item(0).getTextContent()));
            System.out.println("返回值1:" + list.item(0).getTextContent() + " " + "返回值2:" + list.item(1).getTextContent());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return newCityPoint;
    }


    private GeoPoint parseGridNo(String gridNo) {
        GeoPoint newPoint = new GeoPoint();
        String[] gridNoArray = gridNo.split("-");
        double gcj02ZeroPtLon = 121.471454, gcj02ZeroPtLat = 31.233926;
        int quadrant = Integer.parseInt(gridNoArray[0]);
        double lonD_abs = 0.00001 * Integer.parseInt(gridNoArray[1]) - 0.000005;
        double latD_abs = 0.00001 * Integer.parseInt(gridNoArray[2]) - 0.000005;
        switch (quadrant) {
            case 1:
                newPoint.setLon(gcj02ZeroPtLon + lonD_abs);
                newPoint.setLat(gcj02ZeroPtLat + latD_abs);
                break;
            case 2:
                newPoint.setLon(gcj02ZeroPtLon - lonD_abs);
                newPoint.setLat(gcj02ZeroPtLat + latD_abs);
                break;
            case 3:
                newPoint.setLon(gcj02ZeroPtLon - lonD_abs);
                newPoint.setLat(gcj02ZeroPtLat - latD_abs);
                break;
            case 4:
                newPoint.setLon(gcj02ZeroPtLon + lonD_abs);
                newPoint.setLat(gcj02ZeroPtLat - latD_abs);
                break;
        }
        return newPoint;
    }


}
